home *** CD-ROM | disk | FTP | other *** search
/ Isometric Game Programming with DirectX 7.0 / Isometric Game Programming.iso / source / chapter21 / isohex21_1 / isotileplotter.cpp < prev    next >
C/C++ Source or Header  |  2000-07-26  |  3KB  |  154 lines

  1. //IsoTilePlotter.cpp
  2. #include "IsoTilePlotter.h"
  3.  
  4. //plotting function prototypes
  5. POINT IsoHex_SlidePlotTile(POINT ptMap,int iTileWidth,int iTileHeight);
  6. POINT IsoHex_StagPlotTile(POINT ptMap,int iTileWidth,int iTileHeight);
  7. POINT IsoHex_DiamondPlotTile(POINT ptMap,int iTileWidth,int iTileHeight);
  8. POINT IsoHex_RectPlotTile(POINT ptMap,int iTileWidth,int iTileHeight);
  9.  
  10. //constructor
  11. CTilePlotter::CTilePlotter()
  12. {
  13.     //set default map type
  14.     SetMapType(ISOMAP_RECTANGULAR);
  15.  
  16.     //set default tile size
  17.     SetTileSize(1,1);
  18. }
  19.  
  20. //destructor
  21. CTilePlotter::~CTilePlotter()
  22. {
  23.     //intentionally blank
  24. }
  25.  
  26. //set map type
  27. void CTilePlotter::SetMapType(ISOMAPTYPE IsoMapType)
  28. {
  29.     //set the map type
  30.     this->IsoMapType=IsoMapType;
  31.  
  32.     //set the proper plotting function
  33.     switch(IsoMapType)
  34.     {
  35.     case ISOMAP_SLIDE:
  36.         {
  37.             this->IsoHexTilePlotterFn=IsoHex_SlidePlotTile;
  38.         }break;
  39.     case ISOMAP_STAGGERED:
  40.         {
  41.             this->IsoHexTilePlotterFn=IsoHex_StagPlotTile;
  42.         }break;
  43.     case ISOMAP_DIAMOND:
  44.         {
  45.             this->IsoHexTilePlotterFn=IsoHex_DiamondPlotTile;
  46.         }break;
  47.     case ISOMAP_RECTANGULAR:
  48.         {
  49.             this->IsoHexTilePlotterFn=IsoHex_RectPlotTile;
  50.         }break;
  51.     }
  52. }
  53.  
  54. //get map type
  55. ISOMAPTYPE CTilePlotter::GetMapType()
  56. {
  57.     //return the map type
  58.     return(IsoMapType);
  59. }
  60.  
  61. //set tile size
  62. void CTilePlotter::SetTileSize(int iTileWidth,int iTileHeight)
  63. {
  64.     //set width and height
  65.     this->iTileHeight=iTileHeight;
  66.     this->iTileWidth=iTileWidth;
  67. }
  68.  
  69. //get tile width
  70. int CTilePlotter::GetTileWidth()
  71. {
  72.     //return width of tile
  73.     return(iTileWidth);
  74. }
  75.  
  76. //get tile height
  77. int CTilePlotter::GetTileHeight()
  78. {
  79.     //return height of tile
  80.     return(iTileHeight);
  81. }
  82.  
  83. //plot a tile
  84. POINT CTilePlotter::PlotTile(POINT ptMap)
  85. {
  86.     return(IsoHexTilePlotterFn(ptMap,iTileWidth,iTileHeight));
  87. }
  88.  
  89. //actual tile plotting functions
  90. //slide
  91. POINT IsoHex_SlidePlotTile(POINT ptMap,int iTileWidth,int iTileHeight)
  92. {
  93.     //point plotted
  94.     POINT ptPlot;
  95.  
  96.     //plot x
  97.     ptPlot.x=ptMap.x*iTileWidth+ptMap.y*(iTileWidth>>1);
  98.  
  99.     //plot y
  100.     ptPlot.y=ptMap.y*(iTileHeight>>1);
  101.  
  102.     //return plotted coordinate
  103.     return(ptPlot);
  104. }
  105.  
  106. //staggered
  107. POINT IsoHex_StagPlotTile(POINT ptMap,int iTileWidth,int iTileHeight)
  108. {
  109.     //point plotted
  110.     POINT ptPlot;
  111.  
  112.     //plot x
  113.     ptPlot.x=ptMap.x*iTileWidth+(ptMap.y&1)*(iTileWidth>>1);
  114.  
  115.     //plot y
  116.     ptPlot.y=ptMap.y*(iTileHeight>>1);
  117.  
  118.     //return plotted coordinate
  119.     return(ptPlot);
  120. }
  121.  
  122. //diamond
  123. POINT IsoHex_DiamondPlotTile(POINT ptMap,int iTileWidth,int iTileHeight)
  124. {
  125.     //point plotted
  126.     POINT ptPlot;
  127.  
  128.     //plot x
  129.     ptPlot.x=(ptMap.x-ptMap.y)*(iTileWidth>>1);
  130.  
  131.     //plot y
  132.     ptPlot.y=(ptMap.x+ptMap.y)*(iTileHeight>>1);
  133.  
  134.     //return plotted coordinate
  135.     return(ptPlot);
  136. }
  137.  
  138. //rectangular
  139. POINT IsoHex_RectPlotTile(POINT ptMap,int iTileWidth,int iTileHeight)
  140. {
  141.     //point plotted
  142.     POINT ptPlot;
  143.  
  144.     //plot x
  145.     ptPlot.x=ptMap.x*iTileWidth;
  146.  
  147.     //plot y
  148.     ptPlot.y=ptMap.y*iTileHeight;
  149.  
  150.     //return plotted coordinate
  151.     return(ptPlot);
  152. }
  153.  
  154.